var ws, aid, type, uid, gid, spage;
var imgs = [];
document.addEventListener('plusready',function(){
	uid = plus.storage.getItem('uid');
	gid = plus.storage.getItem('gid');
	ws = plus.webview.currentWebview();
	aid = ws.aid;
	type = ws.type;
	spage = ws.spage;
	if(spage != 'Me_drug.html'){
		$('nav').show();
	}else{
		$('header a').show();
	}
	if(gid == 3){	//商家
		$('nav').hide();
	}
	console.log(apiRoot+"/home/medicinal/MedinicalInfo/aid/"+aid+"/type/"+type);
	showWating();
	$.ajax({
		type:"get",
		url:apiRoot+"/home/medicinal/MedinicalInfo",
		data :{
			aid :aid,
			type :type
		},
		complete :function(){
			plus.nativeUI.closeWaiting();
		},
		dataType :'json',
		success :function(data){
//			console.log(JSON.stringify(data)); 
			$('.title').text(data.title);
			$('.price').text('价格：'+data.price+"元"); 
			$.each(data.pro, function(index , value){ 
				imgs.push({"i":index,'img':value.replace('/uploads', webRoot+'/uploads')});
			});
			slider.init(); 
//			var str = '';
//			str = '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data.pro[(data.pro).length-1] +'"/></a></div>';
//			$.each(data.pro, function(index , value){ 
//				str +='<div class="mui-slider-item"><a href="#"><img style="height:180px;" src="'+ webRoot + value +'" /></a></div>'; 
//			});     
//			str += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img style="height:180px;" src="'+ webRoot + data.pro[0] +'"/></a></div>'; 
//			$('.mui-slider-loop').html(str); 
			if(type == 2){
				var arr = ['别名：'+data.alias, '产地：'+data.place, '主治功效：'+data.attend, '储存方法：'+data.store, '使用禁忌：'+data.taboo, '鉴别：'+data.identify, '品类：'+data.category]; 
			}else{
				var arr = ['成分：'+data.component, '适应症：'+data.indication, '储存方法：'+data.store, '使用禁忌：'+data.taboo, '规格：'+data.spec, '用法用量：'+data.dosage, '用法用量：'+data.untoward, '注意事项：'+data.matters, '药物相互作用：'+data.interaction, '药理作用：'+data.worked, '性状：'+data.character, '作用类别：'+data.genre];
			}
			var list = '';
			$.each(arr, function(k, v) {
				list += '<li>'+v+'</li>';
			});
			$('.shop-inf-list').append(list);
			$('.shop-inf-img').html(data.body.replace(/src="/g ,'src="'+webRoot));
		},
		error :function(e){
			errortoast();
			console.log(JSON.stringify(e));
		}
	});
	//点击修改
	$('header a').on('tap',function(){
		var str = type == '2' ? 'Chinese_medicine.html' : 'West_medicine.html';
		goNewPage(str, {spage:ws.id, pid:ws.spage, aid:aid, tid:type});
	})
	//点击加入购物车
	$('.mui-bar-footer').on('tap', function(){
		if(!uid){
			toast('你还未登录');return;
		}
		$.ajax({
			type:"get",
			url:apiRoot+"/home/medicinal/jionCart",
			data:{
				pid :aid,
				uid :uid
			},
			success :function(data){
				if(data > 0){
					toast('添加成功');
				}else{
					toast('添加失败');
				}
			},
			error :function(e){
				console.log(JSON.stringify(e));
				errortoast();
			}
		});
	})
},false)